package com.tangcan.blog.Mapper;

import com.tangcan.blog.Entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    //通过id找user
    @Select("SELECT * FROM User WHERE Id = #{Id}")
    User FindUserById (Integer Id);




    //检查User是否存在
    @Select("SELECT * FROM User WHERE Id = #{Id} OR UserName = #{UserName}")
    User CheckUserExist(User user);

    //通过用户名找用户
    @Select("SELECT * FROM User WHERE UserName = #{UserName}")
    User FindByUserName(String UserName);


    //得到所有User
    @Select("SELECT * FROM User")
    List<User> GetAll();
    //添加用户
    @Insert("INSERT INTO `User` (UserName,PassWord, Authority,UserIcon)VALUES(#{UserName},#{PassWord},#{Authority},#{UserIcon})")
    int AddUser(User user);
//    得到所有管理员用户名

    @Select("SELECT * FROM User WHERE Authority = 'admin'")
    List<User> GetAdminName();

    @Delete("DELETE FROM User WHERE Id = #{Id}")
    int RemoveUser(Integer Id);
    //模糊查询
    @Select("SELECT * FROM User WHERE  Id = #{Condition} OR UserName  LIKE concat('%',#{Condition},'%')" )
    List<User> SearchUser(String Condition);
    //改名字
    @Update("UPDATE User SET UserName = #{UserName} WHERE Id = #{id}")
    int UpdateUserNameById(Integer id, String UserName );
    //改密码
    @Update("UPDATE User SET PassWord = #{PassWord} WHERE Id = #{id}")
    int UpdatePasswdById(Integer id, String PassWord);
    //改头像
    @Update("UPDATE User SET UserIcon = #{UserIcon} WHERE Id = #{id}")
    int UpdateIconById(Integer id, String UserIcon);
}
